#ifndef CMAINWINDOW_H
#define CMAINWINDOW_H

#include <QMainWindow>
#include <QAbstractButton>
#include <QGroupBox>
#include <QPushButton>
#include <qspinbox.h>
#include <QtDataVisualization>


namespace Ui {
class beamquality3d;
}

class beamquality3d : public QMainWindow
{
    Q_OBJECT

public:
    explicit beamquality3d(QWidget *parent = nullptr);
    ~beamquality3d();
    void fillEllipseWithImage(QSurface3DSeries *series, const QPixmap &image);
private slots:
    void onLoadImageClicked();

    Q3DSurface * create3DSurfaceGraph(float z = 0.0f, float major = 30.0f, float minor = 20.0f, float angle = 0.0f);
    Q3DSurface* initialize3DSurfaceGraph();
    void addEllipseTo3DSurface(float z, float major, float minor, float angle, const QColor &color);
    void clearAllEllipses();
    void removeEllipse(int ellipseId);
    QValue3DAxis *createValue3DAxis(QString axisTitle, bool titleVisible = true, float min = -50, float max = 50);
protected:
    void timerEvent(QTimerEvent *event);

private slots:
    void on_angleValueChange(int val);
    void on_themeComboBox_currentIndexChanged(int index);
    void on_scaleSlider_sliderMoved(int position);
    void on_autoSwitchAngleBtn_clicked(bool checked);



private slots:
    void setupEllipseControls();
    void on_addEllipseButton_clicked();
    void on_clearButton_clicked();
    void on_removeButton_clicked();
    void onSeriesClicked(QSurface3DSeries *series);

private:
    Ui::beamquality3d             *ui;            // ui对象指针
    Q3DSurface                  *m_surface;     // 曲面图对象指针
    int                         m_timer;        // 定时器对象
    int                         m_selectedEllipseId; // 当前选中的椭圆ID


    QGroupBox                   *m_ellipseGroupBox;  // 椭圆参数分组框
    QDoubleSpinBox              *m_zValueSpinBox;    // Z值输入框
    QDoubleSpinBox              *m_majorSpinBox;     // 主轴长度输入框
    QDoubleSpinBox              *m_minorSpinBox;     // 次轴长度输入框
    QDoubleSpinBox              *m_angleSpinBox;     // 角度输入框
    QPushButton                 *m_updateButton;     // 更新按钮
    QPushButton                 *m_removeButton;     // 删除按钮

    // 椭圆参数
    float                       m_zValue;       // 椭圆中心Z坐标
    float                       m_majorAxis;    // 椭圆主轴长度
    float                       m_minorAxis;    // 椭圆次轴长度
    float                       m_ellipseAngle; // 椭圆与Z轴夹角
    int                         m_ellipseCount; // 椭圆计数器

};

#endif // CMAINWINDOW_H

